package com.llb666.java.collection;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 线程安全的ArrayList
 * @author liulibin
 */
public class SafeArrayListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        List<String> safeList = Collections.synchronizedList(list);
        safeList.add("aa");
        safeList.add("bb");
        System.out.println(safeList.get(0));

        // -----------------------------------------------
        List<String> safeList2 = new CopyOnWriteArrayList<>();
        safeList2.add("cc");
        safeList2.add("dd");
        System.out.println(safeList2.get(0));
    }
}
